(function() {
  var CategoryDeleteConfirm,
    __hasProp = {}.hasOwnProperty,
    __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };

  this.AdminCategoryListingView = (function(_super) {

    __extends(AdminCategoryListingView, _super);

    function AdminCategoryListingView() {
      return AdminCategoryListingView.__super__.constructor.apply(this, arguments);
    }

    AdminCategoryListingView.prototype.el = $('#content');

    AdminCategoryListingView.prototype.initialize = function() {
      AdminCategoryListingView.__super__.initialize.apply(this, arguments);
      this.model.bind("change", this.render);
      return this.model.fetch();
    };

    AdminCategoryListingView.prototype.render = function() {
      var el, model;
      model = this.model;
      el = $(this.el);
      this.Navigate(model.url(), false, true);
      return this.GetTemplate(SiteMap.Admin.Categories.ListingTemplate, function(compiledTemplate) {
        return el.html(compiledTemplate(model.toJSON()));
      });
    };

    AdminCategoryListingView.prototype.events = {
      "click .search": "search",
      "click .pagination a": "pagination",
      "click th>a": "sort",
      "click .buttons>.create": "create",
      "click .buttons>.delete": "remove",
      "click tbody tr>td:not(.chk)": "edit",
      "change .page-size": "changeSize",
      "click .reset": "reset"
    };

    AdminCategoryListingView.prototype.search = function(event) {
      var filter;
      event.preventDefault();
      Messages.WriteMessage('Apply search.');
      Loading.Start();
      filter = this.model.get('Filter');
      filter.Name = $('#Filter_Name').val();
      this.model.set("Filter", filter, {
        silent: true
      });
      this.model.set("Page", 1, {
        silent: true
      });
      return this.model.fetch();
    };

    AdminCategoryListingView.prototype.reset = function(event) {
      Loading.Start();
      $("#Filter_Name").val('');
      this.model.set("Filter", {
        Name: ''
      }, {
        silent: true
      });
      this.model.set("Page", 1, {
        silent: true
      });
      return this.model.fetch();
    };

    AdminCategoryListingView.prototype.remove = function(event) {
      var categoryDeleteConfirm, form;
      event.preventDefault();
      Messages.Clear();
      form = $(this.el).find("form.listing");
      if (form.find("input:checked").length) {
        categoryDeleteConfirm = new CategoryDeleteConfirm(this);
        return categoryDeleteConfirm.Show("Are you sure?");
      } else {
        return Messages.WriteMessage('Choose one or more author.');
      }
    };

    AdminCategoryListingView.prototype.create = function(event) {
      event.preventDefault();
      Loading.Start();
      return this.Navigate(SiteMap.Admin.Categories.Create, true);
    };

    return AdminCategoryListingView;

  })(ListingView);

  CategoryDeleteConfirm = (function(_super) {

    __extends(CategoryDeleteConfirm, _super);

    CategoryDeleteConfirm.view = null;

    function CategoryDeleteConfirm(view) {
      this.view = view;
    }

    CategoryDeleteConfirm.prototype.Ok = function() {
      var data, form,
        _this = this;
      form = $(this.view.el).find("form.listing");
      data = form.serialize();
      Loading.Start();
      Messages.WriteMessage('Deleting category.');
      return $.post(SiteMap.Admin.Categories.Delete, data, function(response) {
        if ((response.SuccessMessage != null) && response.SuccessMessage.length) {
          Messages.WriteSuccessMessage(response.SuccessMessage);
          return _this.view.model.fetch();
        } else {
          Messages.WriteErrors(response.Errors);
          return Loading.Stop();
        }
      });
    };

    return CategoryDeleteConfirm;

  })(ConfirmDialog);

}).call(this);
